/**
 * 
 */

/**
 * The set length command, takes a new length, which is used to set
 * length after execute is called. The set length command object
 * is defined by the new length and the model, and therefore
 * none of the attributes can be reset after the command has been created
 * @author Sophia Soohoo
 *
 */
public class SetLength extends BrickCommand {

    /**the new length of the brick model*/
    private double newLength = 0.0;
    
    /**
     * The Constructor which sets the model, new length, and
     * makes a momento
     * @param model     the model
     * @param newLength the new length
     */
    public SetLength(BrickModel model, double newLength) {
        setModel(model);
        setMemento(model.makeMemento());
        this.newLength = newLength;
//        System.out.println("new set length");
//        System.out.println("new length = " + newLength);
//        System.out.println("new model" + model.toString());
    }
    
    /**
     * execute the command
     * @throws	CommandException
     * @catch	BrickExceptions and pass to CommandException
     */
    @Override
    public void execute() throws CommandException {
        try {
			getModel().setLength(newLength);
		} catch (BrickException e) {
			throw new CommandException(e.getMessage());
		}
    }

    /**
     * @return the newLength
     */
    public double getNewLength() {
        return newLength;
    }

    /* (non-Javadoc)
     * @see Command#toString()
     */
    @Override
    public String toString() {
        return "new length: " + newLength;
    }

}
